var height=hheight-190;
function initTable(searchValue){
	$('#dataTable').datagrid({
		width:'100%',
		height:height,
		nowrap: true,
		autoRowHeight: false,
		striped: true,
		collapsible:true,
		//idField:'id',
		url:basePath + 'goods/goodsIoApplyd_list.do',
		singleSelect:false,
		columns:[[
		          {field:'id',checkbox:true},
		          {title:'物资名称',field:'goodsName',width:'20%'},
		          {title:'物资规格',field:'goodsSpecification',width:'15%'},
		          {title:'生产厂商编号',field:'manufacturerNo',width:'20%'},
		          {title:'院内库存单位',field:'stockUnit',width:'10%'},
		          {title:'申请数量',field:'applyQty',width:'10%'},
		          {title:'当前科室库存量',field:'stockQty',width:'18%'}
		]],
		pageNumber:1,//当设置了 pagination 特性时，初始化页码 
		pageSize: 10,//当设置了 pagination 特性时，初始化页码尺寸，即每页显示的记录条数，默认为10
		pageList:[10,20,30,40,50],
		queryParams:{//当请求远程数据时，发送的额外参数 
			searchValue:searchValue
		},
		pagination:true,
		rownumbers:true
		
	});
//	var p = $('#dataTable').datagrid('getPager');
//	$(p).pagination({
//		onBeforeRefresh:function(){
//			//alert('before refresh');
//		}
//	});
}
$(function(){
	initTable();
});
//查询
function doSearch(){
	var searchValue = "{";
	  		var goodsName = document.getElementById('goodsName').value;
	  		searchValue += '"goodsName":"'+goodsName+'",';
	  		var goodsSpecification = document.getElementById('goodsSpecification').value;
	  		searchValue += '"goodsSpecification":"'+goodsSpecification+'",';
	  		var manufacturerNo = document.getElementById('manufacturerNo').value;
	  		searchValue += '"manufacturerNo":"'+manufacturerNo+'",';
	  		var stockUnit = document.getElementById('stockUnit').value;
	  		searchValue += '"stockUnit":"'+stockUnit+'",';
	  		var applyQty = document.getElementById('applyQty').value;
	  		searchValue += '"applyQty":"'+applyQty+'",';
	  		var stockQty = document.getElementById('stockQty').value;
	  		searchValue += '"stockQty":"'+stockQty+'",';
	  if(vc.endWith(searchValue,",")){
	  	searchValue = searchValue.substring(0,searchValue.length-1);
	  }
	  searchValue += "}";
	  initTable(searchValue);
}
//添加   ?hospitalNo='+hospitalNo+'&goodsNo'+goodsNo
function do_add() {
	addDialog('增加待出库记录',basePath + 'goods/goodsIoApplyd_show.do',750,450);
}

//删除
function do_delete() {
	var ids ="";
	var rows = $('#dataTable').datagrid('getSelections');
	if(rows.length<1){
		//$.messager.alert('提示','请选择一条记录！','warning');
		alert('请选择一条记录！');
		return;
	}
	for(var i=0;i<rows.length;i++){
		ids+=rows[i].id;
		if(i < rows.length-1){
			ids+=';';
		}
	}
		if(confirm('确认删除选中的记录？')){ 
			$.ajax({ 
				type : "POST", 
				dataType : "json", 
				url:basePath + 'goods/goodsIoApplyd_delete.do', 
				traditional: true,//在struts2下该属性必须有 
				data:{ids:ids}, 
				success:function(result){
					if(result){
						alert(result.message);
						if(result.optType == 'true'){
							initTable(); 
						}
						return;
					}
				}
			});
		}
		// initTable(searchValue);
}
//修改
function do_edit(){
	var rows = $('#dataTable').datagrid('getSelections');
	if(rows.length<1){
		//$.messager.alert('提示','请选择一条记录！','warning');
		alert('请选择一条记录！');
		return;
	}
	else if(rows.length>1){
		//$.messager.alert('提示','只能选择一条记录！','warning');
		alert('只能选择一条记录！');
		return;
	}
	top.addDialog('修改',basePath + 'goods/goodsIoApplyd_edit.do?id='+rows[0].id);
}

//详情
function do_show(){
	var rows = $('#dataTable').datagrid('getSelections');
	if (rows.length < 1) {
		//$.messager.alert('提示','请选择一条记录！','warning');
		alert('请选择一条记录！');
		return;
	} else if (rows.length > 1) {
		//$.messager.alert('提示','只能选择一条记录！', 'warning');
		alert('只能选择一条记录！');
		return;
	}
	top.addDialog('详情',basePath + 'goods/goodsIoApplyd_show.do?id='+rows[0].id);
}